<?php

namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\web\Response;
use app\models\LoginForm;
use app\models\ContactForm;

use app\services\CreativeTemplateService;

class CreativeTemplateController extends AuthController
{
    public $currentHeader = 'header-resource';
    public $currentNav = 'creative-template-nav';
    public $pageTitle = '';

    public function init() {
        parent::init();
        $this->service = new CreativeTemplateService();
    }

    public function actionTemplateList() {
        $this->pageTitle = $this->t('creative-template', 'Creative Template List');
        return $this->show();
    }

    public function actionNewCreativeTemplate() {
        $this->pageTitle = $this->t('creative-template', 'Add New Creative Template');
        return $this->show();
    }

    public function actionCreativeTemplateList() {   
        $this->pageTitle = $this->t('creative-template', 'Creative Template List');
        $this->show();
        if ($this->isPjax()) {
            return $this->renderAjax('creativeTemplateList', [
                'pageTitle' => $this->pageTitle,
                'subTitle' => $this->subTitle
              ]);
        }  else {
            return $this->render('index', [
                'currentHeader'=> $this->currentHeader
            ]);
        }
    }

    public function actionGetAllTemplateList() {
        $templates = $this->service->getAllTemplateList();
        $this->jsonReturn(['data' => $templates]);
    }

    public function actionNewCreativeTemplateHandle() {
        $this->OK($this->t('creative-template', 'Save done!'));
    }

    public function actionWebTemplateEdit() {
        $this->pageTitle = $this->t('creative-template', 'Edit Creative Template');
        return $this->show();
    }

    public function actionAppTemplateEdit() {
        $this->pageTitle = $this->t('creative-template', 'Edit Creative Template');
        return $this->show();
    }

    public function actionAppCreativeTemplatePreview () {
        $this->pageTitle = $this->t('creative-template', 'Creative Template - Preview');
        $this->layout = 'blank';
        return $this->showAjax();
    }

    public function actionWebCreativeTemplatePreview () {
        $this->pageTitle = $this->t('creative-template', 'Add Solution - New Web Creative');
        return $this->showAjax();
    }

}// end
